<template>
  <div class="subject">
    <span>{{ num1 }}</span>
    <span>+</span>
    <span>{{ num2 }}</span>
    <span>=</span>
    <input v-model.trim="answer" type="number" />
    <button :disabled="isput" @click.stop="submit(answer)">提交</button>
  </div>
</template>

<script>
export default {
props:['num1','num2','isput','index','arr'],
data(){
    return {
        answer:''
    }
},
methods:{
    submit(answer){
        if(answer==='') return alert('请输入结果后提交！')
        this.$emit('submitNum',this.index,answer)
    }
},
watch:{
    arr:{
        deep:true,
        handler(arr){
        if(arr.every(item=>item.isput===false)===true)
         {
             this.answer=''
         }
        }
    }
}
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>